{include file="public/layout" /}

{eq name="$editor.editor_select" value="1"}
    {load href="__PUBLIC__/plugins/Ueditor/ueditor.config.js" /}
    {load href="__PUBLIC__/plugins/Ueditor/ueditor.all.min.js" /}
    {load href="__PUBLIC__/plugins/Ueditor/lang/zh-cn/zh-cn.js" /}
{else/}
    {load href="__PUBLIC__/plugins/ckeditor/ckeditor.js" /}
{/eq}

<body style="overflow: auto; cursor: default; -moz-user-select: inherit;background-color:#F4F4F4; ">
<div id="append_parent"></div>
<div id="ajaxwaitid"></div>
{include file="shop_product/left" /}
<div id="geduan_div" class="h15"></div>

<div class="page shop-page shop-ncap-form-default" style="min-width:auto;margin-left:115px;">
    <div class="flexigrid">
        <div class="fixed-bar">
            <div class="item-title">
                <a class="back_xin" href="javascript:history.back();" title="返回"><i class="iconfont e-fanhui"></i></a>
                <!-- <a class="back_sz" href="javascript:void(0);"  data-href="{:url('ShopProduct/help')}" onclick="openHelpframe(this, '设置与帮助', '500px', '100%', 'r');" title="设置与帮助"><i class="iconfont e-shezhi-tongyong"></i></a> -->
                <div class="subject"> <h3>编辑商品</h3> <h5></h5> </div>
                <ul class="tab-base nc-row">
                    <li><a href="javascript:void(0);" data-index='1' class="tab current"><span>基础设置</span></a></li>
                    <li><a href="javascript:void(0);" data-index='2' class="tab "><span>商品详情</span></a></li>
                    <li><a href="javascript:void(0);" data-index='3' class="tab "><span>商品参数</span></a></li>
                    {empty name="$global['web_status']"}
                    <li><a href="javascript:void(0);" data-index='4' class="tab"><span>更多设置</span></a></li>
                    {/empty}
                </ul>
            </div>
        </div>

        <form class="form-horizontal pl10 pr10" id="post_form" action="{:url('ShopProduct/edit', ['source'=>'save'])}" method="post">
            <input type="hidden" name="aid" value="{$field.aid|default='0'}">
            <!-- 基础设置 -->
            <div class="ncap-form-default tab_div_1">
                <div class="div_title"> 基础信息 </div>
                <dl class="row">
                    <dt class="tit"> <label for="title"><em>*</em>商品名称</label> </dt>
                    <dd class="opt">
                        <input type="text" name="title" id="title" value="{$field.title}" class="input-txt" maxlength="200" {eq name="$channelRow.is_repeat_title" value="0"} oninput="check_title_repeat(this, 0);" {/eq}>
                        <!-- &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; -->
                        <!-- 副标题：<input type="text" name="subtitle" id="subtitle" class="w200"> -->
                    </dd>
                </dl>
                <dl class="row">
                    <dt class="tit"> <label for="subtitle">促销语</label> </dt>
                    <dd class="opt"> <textarea rows="5" cols="60" id="subtitle" name="subtitle" style="height: 60px;">{$field.subtitle}</textarea> </dd>
                </dl>
                <dl class="row" style="position: inherit;">
                    <dt class="tit"> <label>所属分类</label> </dt>
                    <input type="hidden" id="action_input_id">
                    <dd class="opt">
                        <div id="ey_category_add" style="display: none;">
                            <div class="ey_top_category">
                               <table class="flex-table autoht wt100" cellpadding="0" cellspacing="0" border="0">
                                   <tbody id="treet1">
                                        {volist name="$arctypeList[0]" id="vo"}
                                        <tr id="{$vo.id}" data-ids="{$vo.ids}" data-names="{$vo.names}" onclick="showSpecify({$vo.id}, {$vo.has_children}, 1);">
                                            <td class="typename wt100">
                                                <div class="typename_div">
                                                    <span class="w140 typeidSpan_0">{$vo.typename}</span>
                                                    {gt name="$vo.has_children" value="0"}<i class="iconfont f-12 ml20 e-right"></i>{/gt}
                                                </div>
                                            </td>
                                        </tr>
                                        {/volist}
                                   </tbody>
                               </table>
                            </div>
                            <div class="ey_top_category subLevel" id="arctypeList_1" style="display: none;">
                               <table class="flex-table autoht wt100" cellpadding="0" cellspacing="0" border="0">
                                   <tbody id="treet1">
                                        {volist name="$arctypeList[1]" id="vo"}
                                        <tr id="{$vo.id}" data-ids="{$vo.ids}" data-names="{$vo.names}" class="typeid_1 parent_id_{$vo.parent_id}" onclick="showSpecify({$vo.id}, {$vo.has_children}, 2);">
                                            <td class="typename wt100">
                                                <div class="typename_div">
                                                    <span class="w140 typeidSpan_1">{$vo.typename}</span>
                                                    {gt name="$vo.has_children" value="0"}<i class="iconfont f-12 ml20 e-right"></i>{/gt}
                                                </div>
                                            </td>
                                        </tr>
                                        {/volist}
                                   </tbody>
                               </table>
                            </div>
                            <div class="ey_top_category subLevel" id="arctypeList_2" style="display: none;">
                               <table class="flex-table autoht wt100" cellpadding="0" cellspacing="0" border="0">
                                   <tbody id="treet1">
                                        {volist name="$arctypeList[2]" id="vo"}
                                        <tr id="{$vo.id}" data-ids="{$vo.ids}" data-names="{$vo.names}" class="typeid_2 parent_id_{$vo.parent_id}" onclick="selectStypeid({$vo.id});">
                                            <td class="typename wt100">
                                                <div class="typename_div">
                                                    <span class="w140 typeidSpan_2">{$vo.typename}</span>
                                                </div>
                                            </td>
                                        </tr>
                                        {/volist}
                                   </tbody>
                               </table>
                            </div>
                        </div>
                        <div class="sDiv2 eyou_goodsTypeid" onclick="goodsTypeid($(this).find('input[id^=input_]').get(0));">
                            <input type="hidden" name="select_ids[]" value="{$arctypeName[0]['ids']}">
                            <input type="text" class="qsbox" readonly="readonly" style="cursor:pointer !important;" id="input_1" data-show="1" data-id="1" data-style="{$arctypeName[0]['style']|default='290'}" data-typeids="{$arctypeName[0]['ids']}" value="{$arctypeName[0]['names']}" placeholder="请选择">
                            <i class="layui-icon-down layui-icon curpoin"></i>
                        </div>
                        <a href="javascript:void(0);" data-id="{if empty($arctypeName)}1{else /}{$arctypeName|count}{/if}" onclick="addTypeid(this);"><i class="iconfont e-zengjia2 color-grey f-20 vertical_middle" title="添加分类"></i></a>
                        <div id="eyou_goodsTypeidHtml">
                            {foreach name="$arctypeName" item="vo" key="k" }
                            {gt name="k" value="0"}
                            <div style="margin-top: 15px;">
                                <div class="sDiv2 eyou_goodsTypeid" onclick="goodsTypeid($(this).find('input[id^=input_]').get(0));">
                                    <input type="hidden" name="select_ids[]" value="{$vo.ids}">
                                    <input type="text" class="qsbox" id="input_{$k+1}" data-show="1" data-id="{$k+1}" data-style="{$vo.style}" data-typeids="{$vo.ids}" value="{$vo.names}" placeholder="请选择">
                                    <i class="layui-icon-down layui-icon curpoin"></i>
                                </div>&nbsp;<a href="javascript:void(0);" onclick="delTypeid(this);"><i class="iconfont e-shanchu2 f-20 color-grey vertical_middle" title="删除"></i></a>
                            </div>
                            {/gt}
                            {/foreach}
                        </div>
                    </dd>
                    <script type="text/javascript">

                        // 默认添加自定义参数
                        $("body").click(function() {
                            $(".ey_top_category, .eyou_goodsTypeid").click(function() {
                                return false;
                            });
                            $("#ey_category_add").hide();
                        });
                        $('body').click();

                        function addTypeid(obj) {
                            var stypeidNum = $('.eyou_goodsTypeid').length;
                            if (parseInt(stypeidNum) >= 10) {
                                showErrorMsg('商品可以属于多个分类，但最多10个');
                                return false;
                            }
                            // 标识ID
                            var id = parseInt($(obj).attr('data-id'));
                            // 获取标识ID的input
                            // var style = parseInt($('#input_' + id).attr('data-style')) + 47;
                            var style = (parseInt(stypeidNum) * 47) + parseInt($('#input_1').attr('data-style'));
                            // 标识ID+1并重载标识ID
                            $(obj).attr('data-id', ++id);
                            // 加载HTML
                            var typeidHtml = [
                                '<div style="margin-top: 15px;">'+
                                    '<div class="sDiv2 eyou_goodsTypeid" onclick="goodsTypeid($(this).find(\'input[id^=input_]\').get(0));">'+
                                        '<input type="hidden" name="select_ids[]">'+
                                        '<input type="text" class="qsbox" id="input_' + id + '" data-show="1" data-id="' + id + '" data-style="' + style + '" placeholder="请选择">'+
                                        '<i class="layui-icon-down layui-icon curpoin"></i>'+
                                    '</div>'+
                                    '&nbsp;<a href="javascript:void(0);" onclick="delTypeid(this);"><i class="iconfont e-shanchu2 color-grey f-20 vertical_middle" title="删除"></i></a>'+
                                '</div>'
                            ];
                            $('#eyou_goodsTypeidHtml').append(typeidHtml);
                        }

                        function delTypeid(obj) {
                            $(obj).parent().remove();
                            var style = 0;
                            $('.eyou_goodsTypeid input[id^=input_]').each(function(index, item){
                                if (index > 0) {
                                    style = (index * 47) + parseInt($('#input_1').attr('data-style'));
                                    $(item).attr('data-style', style);
                                }
                            });
                        }

                        function goodsTypeid(obj) {
                            var id = $(obj).attr('data-id');
                            var show = $(obj).attr('data-show');
                            var style = $(obj).attr('data-style');
                            var typeids = $(obj).attr('data-typeids');
                            if (1 === parseInt(show)) {
                                // 加载正在操作的inputID
                                $('#action_input_id').val(id);
                                // 默认隐藏第二、第三级别分类
                                $('#arctypeList_1, #arctypeList_2').hide();
                                // 去掉选中样式
                                $('.typeidSpan_0, .typeidSpan_1, .typeidSpan_2').css('color', '');
                                // 如果存在分类ID则执行
                                if (typeids) {
                                    // 触发指定ID绑定的事件
                                    typeids = typeids.split(',');
                                    for (var i = 0; i < typeids.length; i++) {
                                        $('#' + typeids[i]).click();
                                    }
                                }
                                // 显示分类选择框
                                $('#ey_category_add').show().css('top', style + 'px');
                            } else {
                                $('#ey_category_add').hide();
                            }
                        }

                        function showSpecify(id, hasChildren, level) {
                            // 点击第一级分类操作
                            if (1 === parseInt(level)) {
                                // 默认隐藏第三级块
                                $('#arctypeList_2').hide();
                                // 如果没有下级则隐藏第二、第三级块
                                if (0 === parseInt(hasChildren)) {
                                    $('#arctypeList_1, #arctypeList_2').hide();
                                    $('.typeidSpan_0').css('color', '');
                                    selectStypeid(id);
                                    return false;
                                }
                            }
                            // 点击第二级分类操作
                            else if (2 === parseInt(level) && 0 === parseInt(hasChildren)) {
                                $('#arctypeList_2').hide();
                                $('.typeidSpan_1').css('color', '');
                                selectStypeid(id);
                                return false;
                            }
                            // 显示指定下级块
                            $('#arctypeList_' + level).show();
                            // 隐藏所有下级分类
                            $('.typeid_' + level).hide();
                            // 显示指定下级分类
                            $('.parent_id_' + id).show();
                            // 点击第一级分类操作
                            if (1 === parseInt(level)) {
                                $('.typeidSpan_0').css('color', '');
                            }
                            // 点击第二级分类操作
                            else if (2 === parseInt(level)) {
                                $('.typeidSpan_1').css('color', '');
                            }
                            // 点击设置选中样式
                            $('#' + id).find('span').css('color', '#3398cc');
                        }

                        function selectStypeid(id) {
                            // 选中的分类ID组
                            var ids = $('#' + id).attr('data-ids');
                            // 选中的分类名称组
                            var names = $('#' + id).attr('data-names');
                            // 设置当前操作的分类
                            var actionInputID = $('#action_input_id').val();
                            // 设置提交的分类ID值
                            $('#input_' + actionInputID).prev().val(ids);
                            // 设置面板显示
                            $('#input_' + actionInputID).val(names).attr('data-typeids', ids);
                            // 隐藏分类选择框
                            $('#ey_category_add').hide();
                            // 将所有三级分类设为未选中
                            $('.typeidSpan_2').css('color', '');
                            // 选中当前点击的分类
                            $('#' + id).find('span').css('color', '#3398cc');
                        }
                    </script>
                </dl>
                <dl class="row">
                    <dt class="tit"> <label>商品标签</label> </dt>
                    <dd class="opt">
                        {volist name="$marketingLabel" id="vo"}
                        <label><input type="radio" name="marketing[]" value="{$vo.types_id}" {if condition="in_array($vo.types_id, $product_label)"}checked{/if}>{$vo.types_names}</label>&nbsp;
                        {/volist}
                    </dd>
                </dl>
                <dl class="row">
                    <dt class="tit"> <label>商品服务</label> </dt>
                    <dd class="opt">
                        {volist name="$serviceLabel" id="vo"}
                        <label><input type="checkbox" name="service[]" value="{$vo.types_id}" {if condition="in_array($vo.types_id, $product_label)"}checked{/if}>{$vo.types_names}</label>&nbsp;
                        {/volist}
                    </dd>
                </dl>
                <dl class="row">
                    <dt class="tit"> <label>商品主图</label> </dt>
                    <dd class="opt">
                        <div class="tab-pane pics" id="tab_proimg">
                            <table class="table table-bordered">
                                <tbody>
                                    <tr>
                                        <td>
                                            <div class="sort-list">
                                                <div class="images_upload" id="litpic_div" style="width: 100px;">
                                                    <div class="ic">
                                                        <div class='upimg'>
                                                            <div class='icaction' style="display: none;">
                                                                <span class="load_images" id="litpic_bigImg"><a href="javascript:void(0);"><i class='iconfont e-chakan f-20'></i></a></span>
                                                                <span class="load_images" id="litpic_update"><a href="javascript:void(0);"><i class='iconfont e-bianji2 f-20'></i></a></span>
                                                            </div>
                                                            <div class='cover-bg' style="display: none;"></div>
                                                            <img id="litpic_img" src=""/>
                                                            <input type="hidden" name="litpic" id="litpic">
                                                            <a class="delect" id="litpic_delect" href="javascript:void(0);" title="删除"></a>
                                                        </div>
                                                    </div>
                                                </div>
                                            </div>
                                            <a href="javascript:void(0);" onclick="GetUploadify(1, '', 'allimg', 'litpic_call_back');" class="img-upload mb15" title="点击上传" id="litpic_a"> <div class="y-line"></div> <div class="x-line"></div> </a>
                                        </td>
                                    </tr>
                                </tbody>
                            </table>
                        </div>
                    </dd>
                </dl>
                <dl class="row">
                    <dt class="tit"> <label for="video_paths">视频介绍</label> </dt>
                    <dd class="opt">
                        <video style='width: 260px; height: 145px;' id='video' controls preload='auto' oncontextmenu='return fase'></video>
                        <div>
                            <input type="text" name="video_paths" id="video_paths" value="{$field.video_paths}" class="input-txt" onchange="videoPaths(this);">
                            <input type="file" id="clickUpload" onchange="videoUpload(this);" style="display: none;">
                            <a href="javascript:void(0);" class="ncap-btn ncap-btn-green" id="videoUpload" onclick="$('#clickUpload').trigger('click');">点击上传</a>
                            <a href="javascript:void(0);" class="ncap-btn ncap-btn-green" onclick="videoClear();">清除</a>
                        </div>
                    </dd>
                </dl>
                <dl class="row">
                    <dt class="tit"> <label>商品轮播图</label> </dt>
                    <dd class="opt">
                        <div class="tab-pane pics" id="tab_proimg">
                            <table class="table table-bordered">
                                <tbody>
                                    <tr>
                                        <td>
                                            <div class="sort-list-img">
                                                {volist name="proimg_list" id="vo" key="k"}
                                                <div class="images_upload images_upload_html" style="display:inline-block;">
                                                    <div class="images_upload_box">
                                                        <input type="hidden" name="proimg[]" value="{$vo['image_url']}">
                                                        <a href="javascript:void(0);" onclick="Images('{$vo[\'image_url\']}',900,600)" class="upimg" title="拖动修改排序">
                                                            <img src="{$vo['image_url']}">
                                                        </a>
                                                        <a href="javascript:void(0)" onclick="ClearPicArr2(this,'{$vo['image_url']}')" class="delect" title="删除"></a>
                                                    </div>
                                                    
                                                </div>
                                                {/volist}
                                                <div class="images_upload"></div>
                                            </div>
                                            <a href="javascript:void(0);" onClick="GetUploadify(30,'','allimg','proimg_call_back');" class="img-upload mb15" title="点击上传"> <div class="y-line"></div> <div class="x-line"></div> </a>
                                        </td>
                                    </tr>
                                </tbody>
                            </table>
                        </div>
                        <!-- 上传图片显示的样板 start -->
                        <div class="images_upload_tpl none">
                            <div class="images_upload images_upload_html">
                                <div class="images_upload_box">
                                    <input type="hidden" name="proimg[]" value="" />
                                    <a href="javascript:void(0);" onClick="" class="upimg" title="拖动修改排序">
                                        <img src="__STATIC__/admin/images/add-button.jpg"/>
                                    </a>
                                    <a href="javascript:void(0)" class="delect" title="删除">&nbsp;&nbsp;</a>
                                </div>
                            </div>
                        </div>
                        <!-- 上传图片显示的样板 end -->
                    </dd>
                </dl>


                <div class="div_title"> 价格库存 </div>
                <dl class="row">
                    <dt class="tit"> <label>商品规格</label> </dt>
                    <dd class="opt">
                        <label><input type="radio" name="goods_spec" value="1" {eq name="$field.goods_spec" value="1"} checked="checked" {/eq} onclick="goodsSpec(1);">单规格</label>&nbsp;
                        <label><input type="radio" name="goods_spec" value="2" {eq name="$field.goods_spec" value="2"} checked="checked" {/eq} onclick="goodsSpec(2);">多规格</label>
                    </dd>
                </dl>
                <!-- <dl class="row">
                    <dt class="tit"> <label>显示划线价</label> </dt>
                    <dd class="opt">
                        <label><input type="radio" name="market_show" value="1" {eq name="$field.market_show" value="1"} checked="checked" {/eq} onclick="marketShow(1);">显示</label>&nbsp;
                        <label><input type="radio" name="market_show" value="2" {eq name="$field.market_show" value="2"} checked="checked" {/eq} onclick="marketShow(2);">隐藏</label>
                    </dd>
                </dl> -->
                <div id="goods_single_spec" {eq name="$field.goods_spec" value="2"} style="display: none;" {/eq}>
                    <dl class="row">
                        <dt class="tit"> <label for="users_price"><em>*</em>销售价</label> </dt>
                        <dd class="opt"> <input type="text" name="users_price" id="users_price" value="{$field.users_price}" class="input-txt"> </dd>
                    </dl>
                    <!-- <dl class="row" id="marketPrice">
                        <dt class="tit"> <label for="market_price">划线价</label> </dt>
                        <dd class="opt"> <input type="text" name="market_price" id="market_price" value="{$field.market_price}" class="input-txt"> </dd>
                    </dl> -->
                    <!-- <dl class="row">
                        <dt class="tit"> <label for="cost_price">成本价</label> </dt>
                        <dd class="opt"> <input type="text" name="cost_price" id="cost_price" value="{$field.cost_price}" class="input-txt"> </dd>
                    </dl> -->
                    <dl class="row">
                        <dt class="tit"> <label for="stock_count"><em>*</em>库存量</label> </dt>
                        <dd class="opt">
                            <input type="text" name="stock_count" id="stock_count" style="width: 10%;" value="{$field.stock_count}">
                            <label> <input type="checkbox" name="stock_show" value="1" checked="checked"> 页面显示商品库存 </label>
                        </dd>
                    </dl>
                </div>
                <div id="goods_multiple_spec" {eq name="$field.goods_spec" value="1"} style="display: none;" {/eq}>
                    <dl class="row">
                        <dt class="tit"> <label for="users_price"></label> </dt>
                        <dd class="opt">
                            <div>
                                <div id='customSpecOptions'>{volist name="SpecSelectName" id="vo"}{$vo}{/volist}</div>
                                <div id="addSpecButton" {eq name="$useSpecNum" value="3"} style="display: none;" {/eq}>
                                    <a href="JavaScript:void(0);" id="addCustomSpec" data-value="{$useSpecNum}" onclick="addCustomSpecName(this);" class="ncap-btn ncap-btn-green ml15">新增规格</a>
                                </div>
                            </div>
                        </dd>
                    </dl>
                    <dl class="row">
                        <dt class="tit"> <label for="users_price">价格/库存</label> </dt>
                        <dd class="opt"> <div id="customSpecTable"> {$HtmlTable} </div> </dd>
                    </dl>
                    <script type="text/javascript">
                        // 商品ID
                        var aid = "{$field.aid}";

                        // 合并单元格
                        MergeCells();

                        // 自定义规格
                        function addCustomSpecName(obj) {
                            // 本次使用的规格数量
                            var specValue = $(obj).attr('data-value');
                            if (3 <= specValue) {
                                showErrorMsg('最多使用三种商品规格大类');
                                return false;
                            }
                            // 自定义规格数量+1覆盖原值
                            $(obj).attr('data-value', ++specValue);

                            // 创建一个自定义规格空数据和表格
                            // layer_loading('正在处理');
                            $.ajax({
                                type: 'post',
                                data: {aid: aid, action: 'name', _ajax: 1},
                                url : "{:url('ShopProduct/ajaxAddCustomSpec')}",
                                dataType: 'json',
                                success: function(res) {
                                    layer.closeAll();
                                    if (1 == res.code) {
                                        // 最大的规格标记ID
                                        var maxSpecMarkID = res.data.spec_mark_id;
                                        // 加载规格选项
                                        var html = [
                                            '<div class="prset-box">'+
                                                '<span class="set-preset-bt mr10" style="display: block;">'+
                                                    '<input type="text" class="zdy-ggname w150" placeholder="规格名称.." onchange="setCustomSpecName(this, ' + maxSpecMarkID + ');">'+
                                                    '<em onclick="delCustomSpecName(this, ' + maxSpecMarkID + ');">'+
                                                        '<i class="fa fa-times-circle" title="关闭" style="margin-left: -20px; margin-top: 8px;"></i>'+
                                                    '</em>'+
                                                    '<span style="margin-left: 10px;"> <label><input type="checkbox">添加图片</label></span>'+
                                                '</span>'+
                                                '<span class="set-preset-box"></span>'+
                                                '<span class="set-preset-con">'+
                                                    '<span class="set-preset-bt mr10">'+
                                                        '<input type="hidden" value="' + res.data.spec_value_id + '">'+
                                                        '<input type="text" class="zdy-ggshuzi w150" placeholder="规格值.." onchange="setCustomSpecValue(this, ' + maxSpecMarkID + ');">'+
                                                    '</span>'+
                                                    '<a href="javascript:void(0);" onclick="addCustomSpecValue(this, ' + maxSpecMarkID + ');" class="preset-bt-shuzi mr10">+增加规格值</a>'+
                                                '</span>'+
                                            '</div>'
                                        ];
                                        $('#customSpecOptions').show().append(html);

                                        // 加载规格表单
                                        loadSpecTable(res.data.htmlTable);
                                        
                                        // 隐藏添加按钮
                                        if (3 == specValue) $('#addSpecButton').hide();
                                    } else {
                                        showErrorMsg(res.msg, 2);
                                    }
                                },
                                error: function(e) {
                                    layer.closeAll();
                                    showErrorAlert(e.responseText);
                                }
                            });
                        }

                        // 规格规格值
                        function addCustomSpecValue(obj, spec_mark_id) {
                            if (spec_mark_id) {
                                layer_loading('正在处理');
                                $.ajax({
                                    type: 'post',
                                    data: {aid: aid, spec_mark_id: spec_mark_id, action: 'value', _ajax: 1},
                                    url : "{:url('ShopProduct/ajaxAddCustomSpec')}",
                                    dataType: 'json',
                                    success: function(res) {
                                        layer.closeAll();
                                        if (1 == res.code) {
                                            // 规格值HTML
                                            var html = [
                                                '<span class="set-preset-bt mr10">'+
                                                    '<input type="hidden" value="' + res.data.spec_value_id + '">'+
                                                    '<input type="text" class="zdy-ggshuzi w150" placeholder="规格值.." onchange="setCustomSpecValue(this, ' + res.data.spec_mark_id + ');">'+
                                                    '<em data-spec_mark_id="' + res.data.spec_mark_id + '" data-spec_value_id="' + res.data.spec_value_id + '" onclick="delCustomSpecValue(this);"><i class="fa fa-times-circle" title="关闭" style="margin-left: -22px;margin-top: 8px;cursor: pointer;"></i></em>'+
                                                '</span>'
                                            ];
                                            // 加载一个规格值 input
                                            $(obj).before(html);
                                            // 加载规格表单
                                            loadSpecTable(res.data.htmlTable);
                                        } else {
                                            showErrorMsg(res.msg, 2);
                                        }
                                    },
                                    error: function(e) {
                                        layer.closeAll();
                                        showErrorAlert(e.responseText);
                                    }
                                });
                            }
                        }

                        // 清除数据库指定数据
                        function delCustomSpecName(obj, spec_mark_id) {
                            if (spec_mark_id) {
                                // 执行处理
                                $.ajax({
                                    type: 'post',
                                    url : "{:url('ShopProduct/ajaxDelCustomSpec', ['_ajax'=>1])}",
                                    data: {aid: aid, spec_mark_id: spec_mark_id, del: 'name'},
                                    dataType: 'json',
                                    success: function(res) {
                                        // 删除当前点击规格块的顶级html
                                        $(obj).parent().parent().remove();
                                        // 加载规格表单
                                        loadSpecTable(res.data.htmlTable);
                                        // 使用规格数量+1覆盖原值
                                        var specValue = $('#addCustomSpec').attr('data-value');
                                        $('#addCustomSpec').attr('data-value', --specValue);
                                        // 显示添加按钮
                                        $('#addSpecButton').show();
                                    }
                                });
                            }
                        }

                        // 清除数据库指定数据
                        function delCustomSpecValue(obj) {
                            // 当选对象
                            var spec_mark_id = $(obj).attr('data-spec_mark_id');
                            var spec_value_id = $(obj).attr('data-spec_value_id');
                            // 执行处理
                            $.ajax({
                                type: 'post',
                                url : "{:url('ShopProduct/ajaxDelCustomSpec', ['_ajax'=>1])}",
                                data: {aid: aid, spec_mark_id: spec_mark_id, spec_value_id: spec_value_id, del: 'value'},
                                dataType: 'json',
                                success: function(res) {
                                    // 删除当前点击规格块的顶级html
                                    $(obj).parent().remove();
                                    // 加载规格表单
                                    loadSpecTable(res.data.htmlTable);
                                }
                            });
                        }

                        // 输入完规格名称后执行
                        function setCustomSpecName(obj, spec_mark_id) {
                            var set_spec_name = $(obj).val();
                            if (spec_mark_id && set_spec_name) {
                                $.ajax({
                                    type: 'post',
                                    dataType: 'json',
                                    data: {aid: aid, spec_mark_id: spec_mark_id, set_spec_name: set_spec_name},
                                    url : "{:url('ShopProduct/ajaxSetCustomSpecName', ['_ajax'=>1])}",
                                    success: function(res) {
                                        if (1 == res.code) {
                                            // 加载规格表单
                                            loadSpecTable(res.data.htmlTable);
                                        } else {
                                            showErrorMsg(res.msg, 2);
                                        }
                                    },
                                    error: function(e) {
                                        layer.closeAll();
                                        showErrorAlert(e.responseText);
                                    }
                                });
                            }
                        }

                        // 输入完规格值后执行
                        function setCustomSpecValue(obj, spec_mark_id) {
                            // 指定的FormID
                            var set_spec_value = $(obj).val();
                            var spec_value_id = $(obj).prev().val();
                            if (set_spec_value && spec_value_id && spec_mark_id) {
                                $.ajax({
                                    type: 'post',
                                    dataType: 'json',
                                    data: {aid: aid, set_spec_value: set_spec_value, spec_value_id: spec_value_id, spec_mark_id: spec_mark_id},
                                    url : "{:url('ShopProduct/ajaxSetCustomSpecValue', ['_ajax'=>1])}",
                                    success: function(res) {
                                        if (1 == res.code) {
                                            // 加载规格表单
                                            loadSpecTable(res.data.htmlTable);
                                        } else {
                                            showErrorMsg(res.msg, 2);
                                        }
                                    },
                                    error: function(e) {
                                        layer.closeAll();
                                        showErrorAlert(e.responseText);
                                    }
                                });
                            }
                        }

                        // 批量设置价格
                        function BulkSetPrice(obj) {
                            layer.prompt({
                                title: false, 
                                shade: layer_shade,
                                formType: 3,
                                id: 'BulkSetPrice',
                                btn: ['确定', '关闭'],
                                closeBtn: 0,
                                success: function(layero, index) {
                                    $("#BulkSetPrice").find('input').attr('placeholder', '批量设置价格');
                                    $("#BulkSetPrice").find('input').attr('onkeyup', "this.value=this.value.replace(/[^\\d.]/g,'')");
                                    $("#BulkSetPrice").find('input').attr('onpaste', "this.value=this.value.replace(/[^\\d.]/g,'')");
                                }
                            }, function(price, index) {
                                // 规格中的价格
                                layer.close(index);
                                $('.spec_price').val(price);
                                // 更新价格，取出最小的值赋值到价格中
                                UpPrice();
                            });
                        }

                        // 更新价格，取出最小的值赋值到价格中
                        function UpPrice() {
                            var specPriceArray = new Array();
                            $('.spec_price').each(function() {
                                specPriceArray.push($(this).val());
                            });
                            // 取出最小值
                            var minValue = Math.min.apply(Math, specPriceArray);
                            $('#users_price').val(minValue);
                        }

                        // 批量设置划线价
                        function bulkSetMarketPrice(obj) {
                            layer.prompt({
                                title: false, 
                                shade: layer_shade,
                                formType: 3,
                                id: 'setMarketPrice',
                                btn: ['确定', '关闭'],
                                closeBtn: 0,
                                success: function(layero, index) {
                                    $("#setMarketPrice").find('input').attr('placeholder', '批量设置划线价');
                                    $("#setMarketPrice").find('input').attr('onkeyup', "this.value=this.value.replace(/[^\\d.]/g,'')");
                                    $("#setMarketPrice").find('input').attr('onpaste', "this.value=this.value.replace(/[^\\d.]/g,'')");
                                }
                            }, function(price, index) {
                                // 规格中的价格
                                layer.close(index);
                                $('.spec_market_price').val(price);
                                // 更新价格，取出最小的值赋值到价格中
                                upMarketPrice();
                            });
                        }

                        // 更新价格，取出最小的值赋值到价格中
                        function upMarketPrice() {
                            var specMarketPriceArray = new Array();
                            $('.spec_market_price').each(function() {
                                specMarketPriceArray.push($(this).val());
                            });
                            // 取出最小值
                            var minValue = Math.min.apply(Math, specMarketPriceArray);
                            $('#market_price').val(minValue);
                        }

                        // 批量设置成本价
                        function bulkSetCostPrice(obj) {
                            layer.prompt({
                                title: false, 
                                shade: layer_shade,
                                formType: 3,
                                id: 'setMarketPrice',
                                btn: ['确定', '关闭'],
                                closeBtn: 0,
                                success: function(layero, index) {
                                    $("#setMarketPrice").find('input').attr('placeholder', '批量设置划线价');
                                    $("#setMarketPrice").find('input').attr('onkeyup', "this.value=this.value.replace(/[^\\d.]/g,'')");
                                    $("#setMarketPrice").find('input').attr('onpaste', "this.value=this.value.replace(/[^\\d.]/g,'')");
                                }
                            }, function(price, index) {
                                // 规格中的价格
                                layer.close(index);
                                $('.spec_cost_price').val(price);
                                // 更新价格，取出最小的值赋值到价格中
                                upCostPrice();
                            });
                        }

                        // 更新价格，取出最小的值赋值到价格中
                        function upCostPrice() {
                            var specCostPriceArray = new Array();
                            $('.spec_cost_price').each(function() {
                                specCostPriceArray.push($(this).val());
                            });
                            // 取出最小值
                            var minValue = Math.min.apply(Math, specCostPriceArray);
                            $('#cost_price').val(minValue);
                        }

                        // 批量设置库存
                        function BulkSetStock(obj) {
                            layer.prompt({
                                title: false, 
                                shade: layer_shade,
                                formType: 3,
                                id: 'BulkSetStock',
                                btn: ['确定', '关闭'],
                                closeBtn: 0,
                                success: function(layero, index) {
                                    $("#BulkSetStock").find('input').attr('placeholder', '批量设置库存');
                                    $("#BulkSetStock").find('input').attr('onkeyup', "this.value=this.value.replace(/[^\\d.]/g,'')");
                                    $("#BulkSetStock").find('input').attr('onpaste', "this.value=this.value.replace(/[^\\d.]/g,'')");
                                }
                            }, function(stock, index) {
                                layer.close(index);
                                // 单个库存
                                $('.spec_stock').val(stock);
                                $('.spec_stock').attr('data-old_stock', stock);
                                spec_stock = Number($('.spec_stock').length) * Number(stock);
                                $('#stock_count').val(spec_stock);
                            });
                        }

                        // 更新库存量
                        function UpStock(obj) {
                            var stock_count = $('#stock_count').val();
                            var new_stock = $(obj).val();
                            var old_stock = $(obj).attr('data-old_stock');
                            $(obj).attr('data-old_stock', new_stock);
                            if (Number(old_stock) > Number(new_stock)) {
                                new_stock   = Number(old_stock) - Number(new_stock);
                                stock_count = Number(stock_count) - Number(new_stock);
                            } else {
                                new_stock   = Number(new_stock) - Number(old_stock);
                                stock_count = Number(stock_count) + Number(new_stock);
                            }
                            $('#stock_count').val(stock_count);
                        }

                        // 加载规格表单
                        function loadSpecTable(htmlTable) {
                            if (htmlTable) {
                                // 加载规格框架
                                $('#customSpecTable').html(htmlTable);
                                // 合并单元格
                                MergeCells();
                                // 是否隐藏划线价格
                                marketShow();
                            }
                        }

                        // 合并单元格
                        function MergeCells() {
                            var tab = document.getElementById("spec_input_tab");
                            var maxCol = 2, val, count, start; 
                            if (tab != null) {
                                for (var col = maxCol - 1; col >= 0; col--) {
                                    count = 1;
                                    val = "";
                                    for (var i = 0; i < tab.rows.length; i++) {
                                        if (val == tab.rows[i].cells[col].innerHTML) {
                                            count++;
                                        } else {
                                            if (count > 1) { //合并
                                                start = i - count;
                                                tab.rows[start].cells[col].rowSpan = count;
                                                for (var j = start + 1; j < i; j++) {
                                                    tab.rows[j].cells[col].style.display = "none";
                                                }
                                                count = 1;
                                            }
                                            val = tab.rows[i].cells[col].innerHTML;
                                        }
                                    }
                                    if (count > 1) { //合并，最后几行相同的情况下
                                        start = i - count;
                                        tab.rows[start].cells[col].rowSpan = count;
                                        for (var j = start + 1; j < i; j++) {
                                            tab.rows[j].cells[col].style.display = "none";
                                        }
                                    }
                                }
                            }
                        }
                    </script>
                </div>
                <dl class="row">
                    <dt class="tit"> <label for="goods_unit">商品单位</label> </dt>
                    <dd class="opt"> 
                        <input type="text" name="goods_unit" id="goods_unit" value="{$usersConfig.goods_unit}" class="input-txt" disabled="disabled" style="width: 10%;"> 
                        <p class="notic">请在设置-基础信息-商城设置里设置</p>
                    </dd>
                </dl>
                <dl class="row">
                    <dt class="tit"> <label>显示销量</label> </dt>
                    <dd class="opt">
                        <label><input type="radio" name="sales_show" value="1" {eq name="$field.sales_show" value="1"} checked="checked" {/eq} onclick="salesShow(1);">显示</label>&nbsp;
                        <label><input type="radio" name="sales_show" value="2" {eq name="$field.sales_show" value="2"} checked="checked" {/eq} onclick="salesShow(2);">隐藏</label>
                        <p class="notic">显示销量=实际销量+虚拟销量</p>
                    </dd>
                </dl>
                <dl class="row" id="virtualSales">
                    <dt class="tit"> <label for="virtual_sales">虚拟销量</label> </dt>
                    <dd class="opt"> <input type="text" name="virtual_sales" id="virtual_sales" value="{$field.virtual_sales}" class="input-txt"> </dd>
                </dl>


                <div class="div_title"> 物流设置 </div>
                <dl class="row">
                    <dt class="tit"> <label>运费设置</label> </dt>
                    <dd class="opt">
                        <label><input type="radio" name="freight_fee_set" value="1" {eq name="$field.freight_fee_set" value="1"} checked="checked" {/eq} onclick="freightFeeSet(1);">包邮</label>&nbsp;
                        <label><input type="radio" name="freight_fee_set" value="2" {eq name="$field.freight_fee_set" value="2"} checked="checked" {/eq} onclick="freightFeeSet(2);">选择模板</label>
                    </dd>
                </dl>
                <dl class="row" id="freightFeeSet" {eq name="$field.freight_fee_set" value="1"} style="display: none;" {/eq}>
                    <dt class="tit"> <label>选择模板</label> </dt>
                    <dd class="opt">
                        <select name="freight_fee_tpl" id="freight_fee_tpl">
                            <option value="0">请选择</option>
                            {volist name="$template" id="tpl"}
                            <option value="{$tpl.template_id}" {eq name="$tpl.template_id" value="$field.freight_fee_tpl"} selected {/eq}>{$tpl.template_name}</option>
                            {/volist}
                        </select>
                        &nbsp; &nbsp;
                        <a href="JavaScript:void(0);" onclick="refreshFreightFeeTpl({$field.freight_fee_tpl});">刷新</a>
                        &nbsp; &nbsp;
                        <a href="{:url('ShopFreight/index')}" target="_blank">添加模板</a>
                    </dd>
                </dl>
                <script type="text/javascript">
                    // 运费设置
                    function freightFeeSet(freight_fee_set) {
                        if (1 === parseInt(freight_fee_set)) {
                            $('#freightFeeSet').hide();
                        } else if (2 === parseInt(freight_fee_set)) {
                            $('#freightFeeSet').show();
                        }
                    }

                    // 刷新运费模板
                    function refreshFreightFeeTpl(freight_fee_tpl) {
                        layer_loading('正在处理');
                        $.ajax({
                            type: 'post',
                            url : "{:url('ShopProduct/ajaxGetTemplateList')}",
                            data: {freight_fee_tpl: freight_fee_tpl, _ajax: 1},
                            dataType: 'json',
                            success : function(res) {
                                layer.closeAll();
                                if (1 === parseInt(res.code)) {
                                    $('#freight_fee_tpl').empty().html(res.data);
                                } else {
                                    // 提示内容
                                    showErrorMsg(res.msg);
                                }
                            },
                            error: function(e) {
                                showErrorAlert(e.responseText);
                            }
                        });
                    }
                </script>


                <div class="div_title"> 商品状态 </div>
                <dl class="row">
                    <dt class="tit"> <label>上架设置</label> </dt>
                    <dd class="opt">
                        <label><input type="radio" name="status" value="1" {eq name="$field.status" value="1"} checked="checked" {/eq}>立即上架</label>&nbsp;
                        <label><input type="radio" name="status" value="0" {eq name="$field.status" value="0"} checked="checked" {/eq}>放入仓库</label>
                    </dd>
                </dl>
                <div style="height: 30px;display: block;"></div>
            </div>
            <!-- 基础设置 -->

            <!-- 商品详情 -->
            <div class="ncap-form-default tab_div_2" style="display: none;">
                {include file="archives/get_field_addonextitem" /}
            </div>
            <!-- 商品详情 -->

            <!-- 商品参数 -->
            <div class="ncap-form-default tab_div_3" style="display: none;">
                <dl class="row ml120">
                    <dd class="opt">
                        <div id="system_param" style="display: block;">
                            <div class="selectPro_arg">
                                <select name="attrlist_id" id="attrlist_id" onchange="attrListSelect(this);" style="margin-bottom: 10px;">
                                    <option value="0">请选择商品参数</option>
                                    {volist name="AttrList" id="vo"}
                                        <option value="{$vo.list_id}" {eq name="$vo.list_id" value="$field.attrlist_id"}selected{/eq}>{$vo.list_name}</option>
                                    {/volist}
                                </select>
                                &nbsp; &nbsp; &nbsp;
                                <p>商品可以添加自定义商品参数，也可以通过参数模板批量设置商品参数</p>
                            </div>
                            <dl class="row" style="border: unset;">
                                <dt class="sort-e lh40 pl0 text-l10" style=" background: #f4f6f8;">排序</dt>
                                <dt class="tit lh40 pl5 tc" style=" background: #f4f6f8;"> 参数名称</dt>
                                <dd class="opt w350 lh40 text-l10" style=" background: #f4f6f8;">参数值</dd>
                            </dl>
                            <div id='AttrSelectName' style="margin: 1px;">{$canshu}</div>
                            <div id='customParam' style="margin: 1px;">
                                <input type="hidden" name="del_attr_id" value="{$delAttrID}">
                                {volist name="$customParam" id="vo"}
                                <dl class="row">
                                    <dt class="sort-e pl0"> <input class="tc" type="text" size="4" name="sort_order[{$vo.attr_id}]" value="{$vo.sort_order}"> </dt>
                                    <dt class="tit pl5 tc"> <input type="text" size="10" name="attr_name[{$vo.attr_id}]" value="{$vo.attr_name}"> </dt>
                                    <dd class="opt w350 pl5">
                                        <input type="text" size="40" name="attr_value[{$vo.attr_id}]" value="{$vo.attr_value}">
                                        <a class="text_a" href="javascript:void(0);" onClick="delCustomParam(this);">&nbsp;删除</a>
                                    </dd>
                                </dl>
                                {/volist}
                            </div>
                        </div>
                        <a href="JavaScript:void(0);" id="addCustomParam" data-attr_id="{$maxAttrID}" onclick="addCustomParam(this);" class="ncap-btn ncap-btn-green">添加参数</a>
                    </dd>
                </dl>
                <script type="text/javascript">
                    // 添加自定义参数
                    function addCustomParam(obj) {
                        var maxAttrID = $(obj).attr('data-attr_id');
                        // 规格值HTML
                        var html = [
                            '<dl class="row">'+
                                '<dt class="sort-e pl0"> <input class="tc" type="text" size="4" name="sort_order['+maxAttrID+']" placeholder="100"> </dt>'+
                                '<dt class="tit pl5 tc"> <input type="text" size="10" name="attr_name['+maxAttrID+']" placeholder="输入参数名称"> </dt>'+
                                '<dd class="opt w350 pl5">'+
                                    '<input type="text" size="40" name="attr_value['+maxAttrID+']" placeholder="输入参数值">'+
                                    '<a class="text_a" href="javascript:void(0);" onClick="delCustomParam(this);">&nbsp;&nbsp;删除</a>'+
                                '</dd>'+
                            '</dl>'
                        ];
                        // 加载一个规格值 input
                        $('#customParam').append(html);
                        // 自定义参数数量+1覆盖原值
                        $(obj).attr('data-attr_id', ++maxAttrID);
                    }

                    // 删除自定义参数
                    function delCustomParam(obj) {
                        $(obj).parent().parent().remove();
                    }

                    // 参数选择
                    function attrListSelect(obj) {
                        var aid = 0;
                        var list_id = $(obj).val();
                        if (parseInt(list_id) < 1) {
                            $("#AttrSelectName").empty();
                            return false;
                        }
                        // 商品栏目切换时 ajax 调用返回不同的属性输入框
                        $.ajax({
                            type:'GET',
                            data:{aid: aid, list_id: list_id, _ajax: 1}, 
                            url :"{:url('ShopProduct/ajax_get_shop_attr_input')}",
                            success:function(data) {
                                $("#AttrSelectName").empty().append(data);
                            }
                        });
                    }
                </script>
            </div>
            <!-- 商品参数 -->

            <!-- 更多设置 -->
            <div class="ncap-form-default tab_div_4" style="display: none;">
                <dl class="row">
                    <dt class="tit"> <label for="seo_title">SEO标题</label> </dt>
                    <dd class="opt">
                        <input type="text" value="{$field.seo_title}" name="seo_title" id="seo_title" class="input-txt">
                    </dd>
                </dl>
                <dl class="row">
                    <dt class="tit"> <label for="seo_keywords">SEO关键词</label> </dt>
                    <dd class="opt">          
                        <textarea rows="5" cols="60" id="seo_keywords" name="seo_keywords" style="height:40px;">{$field.seo_keywords}</textarea>
                    </dd>
                </dl>
                <dl class="row">
                    <dt class="tit"> <label for="seo_description">SEO描述</label> </dt>
                    <dd class="opt">          
                        <textarea rows="5" cols="60" id="seo_description" name="seo_description" style="height:60px;">{$field.seo_description}</textarea>
                    </dd>
                </dl>
                <!-- #weapp_UsersGroup_content_users_id={$field.users_id}#--><!-- #weapp_UsersGroup_content# -->
                <dl class="row">
                    <dt class="tit"> <label for="add_time">发布时间</label> </dt>
                    <dd class="opt">
                        <input type="text" class="input-txt" id="add_time" name="add_time" value="{$field.add_time|date='Y-m-d H:i:s',###}" autocomplete="off">
                        <span class="add-on input-group-addon"> <i class="glyphicon glyphicon-calendar fa fa-calendar"></i></span>
                    </dd>
                </dl>
                <dl class="row">
                    <dt class="tit"> <label for="tempview">商品模板</label> </dt>
                    <dd class="opt">
                        <select name="tempview" id="tempview">
                            {volist name='$templateList' id='vo'}
                            <option value="{$vo}" {eq name='$vo' value='$tempview'}selected{/eq}>{$vo}</option>
                            {/volist}
                        </select>
                        <input type="hidden" name="type_tempview" value="{$tempview}" />
                    </dd>
                </dl>
                <dl class="row {notin name='$seo_pseudo' value='2'}no-grey{/notin}">
                    <dt class="tit"> <label>自定义文件名</label> </dt>
                    <dd class="opt">
                        <input type="text" {notin name='$seo_pseudo' value='2'}readonly="readonly" title="仅在静态模式下使用"{/notin} value="{$field.htmlfilename}" name="htmlfilename" id="htmlfilename" autocomplete="off" onkeyup="this.value=this.value.replace(/[^\w\-]/g,'-');" onpaste="this.value=this.value.replace(/[^\w\-]/g,'-');" class="input-txt {notin name='$seo_pseudo' value='2'}no-drop{/notin}">.html
                    </dd>
                </dl>
            </div>
            <!-- 更多设置 -->
            
            <div class="ncap-form-default">
                <div class="bot2" style="left: 150px;">
                    <input type="hidden" id="editor_addonFieldExt" value="">
                    <a href="JavaScript:void(0);" onclick="check_submit();" class="ncap-btn-big ncap-btn-green" id="submitBtn">确认提交</a>
                    <a class="ncap-btn-big ncap-btn-no" href="javascript:history.back();" title="返回">返回</a>
                </div>
            </div> 
        </form>
    </div>
</div>

<script type="text/javascript">
    // function selectStypeid() {
    //     var url = "{:url('ShopProduct/select_stypeid')}";
    //     url = url + '&get_stypeid=' + $('#stypeid').val();
    //     layer.open({
    //         type: 2,
    //         move: false,
    //         closeBtn: false,
    //         title: '选择分类',
    //         shade: layer_shade,
    //         area: ['80%', '90%'],
    //         btn: ['确定', '关闭'],
    //         content: url,
    //         yes: function(index, layero) {
    //             var body = layer.getChildFrame('body', index);
    //             var stypeid = body.find('#post_stypeid').val();
    //             layer.close(index);
    //             $('#stypeid').val(stypeid);
    //             loadSelectStypeid(stypeid);
    //         }
    //     });
    // }

    // 加载分类名称
    // var inputStypeid = $('#stypeid').val();
    // loadSelectStypeid(inputStypeid);
    // function loadSelectStypeid(stypeid) {
    //     if (stypeid) {
    //         var url = "{:url('ShopProduct/select_stypeid')}";
    //         $.ajax({
    //             url : url,
    //             type: 'post',
    //             data: {stypeid: stypeid, _ajax: 1},
    //             dataType: 'json',
    //             success: function(res) {
    //                 $('#selectStypeid').html(res.data);
    //             }
    //         });
    //     } else {
    //         $('#stypeid').val('');
    //         $('#selectStypeid').html('');
    //     }
    // }

    // function delStypeid(obj) {
    //     var stypeid = $(obj).data('id');
    //     if (stypeid) {
    //         var stypeidStr = $('#stypeid').val();
    //         var stypeidArr = stypeidStr.split(',');
    //         var index = $.inArray(String(stypeid), stypeidArr);
    //         if (-1 < index) stypeidArr.splice(index, 1);
    //         stypeidStr = stypeidArr.join(',');
    //         $('#stypeid').val(stypeidStr);
    //         $(obj).parent().remove();
    //     }
    // }
</script>

<script type="text/javascript">
    // 鼠标事件，加载查看大图和更新图片
    $(document).ready(function() {
        $(".upimg").live('mouseover', function() {
            $(this).find('div.icaction').show();
            $(this).find('div.cover-bg').show();
        }).live('mouseout', function() {
            $(this).find('div.icaction').hide();
            $(this).find('div.cover-bg').hide();
        });
    });

    // 自定加载图片
    var litpic = "{$field.litpic}";
    if (litpic) litpic_call_back(litpic);
    // 商品主图回调加载
    function litpic_call_back(paths) {
        $('#litpic_a').hide();
        $('#litpic_div').show();
        $('#litpic_div #litpic').val(paths);
        $('#litpic_div #litpic_img').attr('src', paths);
        $('#litpic_div #litpic_delect').attr('onclick', "litpicClear();");
        $('#litpic_div #litpic_bigImg').attr('onclick', "Images('"+paths+"', 900, 600);");
        $('#litpic_div #litpic_update').attr('onclick', "GetUploadify(1, '', 'allimg', 'litpic_call_back');");
    }

    // 商品主图清除
    function litpicClear() {
        $('#litpic_a').show();
        $('#litpic_div').hide();
        $('#litpic_div #litpic').val('');
        $('#litpic_div #litpic_img').attr('src', '');
        $('#litpic_div #litpic_delect').attr('onclick', '');
        $('#litpic_div #litpic_bigImg').attr('onclick', '');
        $('#litpic_div #litpic_update').attr('onclick', '');
    }

    // 本地上传
    function videoUpload(obj) {
        // 获取文件路径名
        var file = $(obj)[0].files[0];

        // 验证上传格式
        var fileName = file.name;
        var fileExt = fileName.substr(fileName.lastIndexOf('.')).toLowerCase();
        var ext = judgeExt(fileExt);
        if (ext == -1) {
            showErrorMsg('不支持选中的视频格式，可在附件设置中修改');
            return false;
        }

        // 验证上传大小
        var size = "{$upload_max_filesize}";
        if (file.size > size) {
            showErrorMsg('视频大小超过限制，可在附件设置中修改');
            return false;
        }

        // 定义上传数据
        var formData = new FormData();
        formData.append('file', file);

        // 执行上传
        layer_loading('上传本地');
        $.ajax({
            type: 'post',
            url : "{:url('Ueditor/upVideo', ['savepath'=>'media'])}",
            data: formData,
            contentType: false,
            processData: false,
            dataType: 'json',
            xhr: function () {
                myXhr = $.ajaxSettings.xhr();
                if (myXhr.upload) {
                    myXhr.upload.addEventListener('progress', function(e) {
                        var curr = e.loaded;
                        var total = e.total;
                        process = parseInt(curr / total * 100);
                        $("#videoUpload").html('上传中...'+process+"%");
                    });
                }
                return myXhr;
            },
            success: function (res) {
                layer.closeAll();
                $("#videoUpload").html('上传成功');
                setTimeout(function() {
                    $('#videoUpload').html('本地上传');
                }, 2000);
                if ("SUCCESS" == res.state) {
                    $('#video').attr('src', res.url);
                    $("#video_paths").val(res.url);
                } else {
                    showErrorMsg(res.msg);
                }
            }
        });
    }

    // 自定加载视频
    var video_paths = "{$field.video_paths}";
    if (video_paths) videoPaths(null, video_paths);
    // 手动更新视频路径
    function videoPaths(obj, video_paths) {
        if (!obj && video_paths) {
            $('#video').attr('src', video_paths);
        } else {
            $('#video').attr('src', $(obj).val());
        }
    }

    // 视频清除
    function videoClear() {
        $('#video_paths').val('');
        $('#video').attr('src', '');
    }

    // 验证格式
    function judgeExt(ext) {
        var type = "{$media_type}";
        var extArr = [];
        extArr = type.split("|");
        var ext = ext.replace(".", "");
        return extArr.indexOf(ext);
    }

    // 商品单、多规格选择
    function goodsSpec(goods_spec) {
        if (1 === parseInt(goods_spec)) {
            $('#goods_single_spec').show();
            $('#goods_multiple_spec').hide();
        } else if (2 === parseInt(goods_spec))  {
            $('#goods_single_spec').hide();
            $('#goods_multiple_spec').show();
        }
    }

    // 销量显示、隐藏
    function salesShow(sales_show) {
        if (1 === parseInt(sales_show)) {
            $('#virtualSales').show();
        } else if (2 === parseInt(sales_show)) {
            $('#virtualSales').hide();
        }
    }

    // 划线价显示、隐藏
    function marketShow(market_show) {
        if (undefined === market_show) market_show = $('input:radio[name="market_show"]:checked').val();
        if (1 === parseInt(market_show)) {
            $('#marketPrice, .market_price_td').show();
        } else if (2 === parseInt(market_show)) {
            $('#marketPrice, .market_price_td').hide();
        }
    }
</script>

<script type="text/javascript">
    $(function () {
        // 选项卡切换列表
        $('.tab-base').find('.tab').click(function(){
            $('.tab-base').find('.tab').each(function(){
                $(this).removeClass('current');
            });
            $(this).addClass('current');
            var tab_index = $(this).data('index');          
            $(".tab_div_1, .tab_div_2, .tab_div_3, .tab_div_4").hide();          
            $(".tab_div_" + tab_index).show();
            layer.closeAll();
        });
    });

    layui.use('laydate', function() {
        var laydate = layui.laydate;
        var myDate = new Date;
        var year = myDate.getFullYear(); //获取当前年
        var mon = myDate.getMonth() + 1; //获取当前月
        var day = myDate.getDate(); //获取当前日
        var mark_time = year + "-" + mon + "-" + day;//当前日期
        var mark = [];
        mark[mark_time] = '';

        laydate.render({
            elem: '#add_time'
            ,type: 'datetime'
            ,mark: mark
            ,ready: function(date) {
                if (!$('#add_time').val() || mark_time != $('#add_time').val()) {
                    $('.laydate-day-mark').removeClass('laydate-day-mark').parent().addClass('today_laydate_mark');
                    $('.today_laydate_mark').removeClass('layui-this');
                }
            }
            ,change: function(value, date, endDate) {
                $('.laydate-day-mark').addClass('today_laydate_mark').removeClass('laydate-day-mark');
            }
        });
    })
    
    // 判断输入框是否为空
    function check_submit() {
        if ($.trim($('input[name=title]').val()) == '') {
            showErrorMsg('标题不能为空！');
            $($('.tab-base').find('.tab')[0]).trigger('click'); 
            $('input[name=title]').focus();
            return false;
        }
        
        layer_loading('正在处理');

        setTimeout(function () {
            editor_auto_210607();
            $('#post_form').submit();
        }, 1);
    }

    // 上传产品相册回调函数
    function proimg_call_back(paths) {
        var last_div = $(".images_upload_tpl").html();
        for (var i = 0; i < paths.length; i++) {
            if ($(".sort-list-img .images_upload_html").length > 0) {
                $(".sort-list-img .images_upload_html:last").after(last_div);  // 插入一个 新图片
            } else {
                $(".sort-list-img .images_upload:last").before(last_div);  // 插入一个 新图片
            }
            // $(".sort-list-img .images_upload_html:last").find('a:eq(0)').attr('href',paths[i]).attr('onclick','').attr('target', "_blank");// 修改他的链接地址
            $(".sort-list-img .images_upload_html:last").find('a:eq(0)').attr('href','javascript:void(0);').attr('onclick','Images("'+paths[i]+'",900,600)');// 修改他的链接地址
            $(".sort-list-img .images_upload_html:last").find('img').attr('src',paths[i]);// 修改他的图片路径
            $(".sort-list-img .images_upload_html:last").find('a:eq(1)').attr('onclick',"ClearPicArr2(this,'"+paths[i]+"')").text('');
            $(".sort-list-img .images_upload_html:last").find('input').val(paths[i]); // 设置隐藏域 要提交的值
        }             
    }
    
    // 上传之后删除组图input
    function ClearPicArr2(obj,path) {
        $(obj).parent().parent().remove();
        $.ajax({
            type:'POST',
            url:"{:url('Uploadimgnew/delupload')}",
            data:{action:"del", filename:path,_ajax:1},
            success: function(){}
        });
    }

    /** 以下产品相册的拖动排序相关 js*/
    $( ".sort-list-img" ).sortable({
        start: function( event, ui) {
            
        },
        stop: function( event, ui ) {

        }
    });
    // 因为他们要拖动，所以尽量设置他们的文字不能选择
    $(".sort-list-img").disableSelection();
</script>

<script type="text/javascript">
    try{
        var mt20_1649209614 = sessionStorage.getItem("mt20_1649209614");
        if (mt20_1649209614 == 1) {
            $("#geduan_div").removeClass("h15");
        } else {
            $("#geduan_div").addClass("h15");
        }
    }catch(e){}
</script>
{include file="public/footer" /}